//
//  DIYFSCalendarCellForCalendar.swift
//  GreenDeal
//
//  Created by Moennig Q on 2023/3/28.
//

import UIKit
import FSCalendar
import SnapKit
class DIYFSCalendarCellForCalendar: FSCalendarCell {
    weak var selectBackLayer: CAShapeLayer!//自定义选中的背景颜色
    weak var dateLabel: ContentLabel!
    weak var weatherImageView: UIImageView!
    weak var jobCntLabel: ContentLabel!//自定义
    required init!(coder aDecoder: NSCoder!) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        //selectBackLayer
        let selectBackLayer = CAShapeLayer()
        selectBackLayer.fillColor = UIColor(hexStr: "#FFFFFF99").cgColor
        selectBackLayer.actions = ["hidden": NSNull()]
        self.contentView.layer.addSublayer(selectBackLayer)//insertSublayer(selectBackLayer, below: self.titleLabel!.layer)
        self.selectBackLayer = selectBackLayer
        self.selectBackLayer.isHidden = true
        //date label
        let dateLabel = ContentLabel(R.font.interRegular(size: 16))
        self.dateLabel = dateLabel
        self.contentView.addSubview(self.dateLabel)
        self.dateLabel.snp.makeConstraints { make in
            make.top.equalTo(8)
            make.centerX.equalToSuperview()
            make.height.width.greaterThanOrEqualTo(0)
        }
        //job cnt label
        let jobCntLabel = ContentLabel(R.font.interMedium(size: 11),hexStr: "#FFFFFF")
        jobCntLabel.layer.cornerRadius = 8
        jobCntLabel.backgroundColor = UIColor(hexStr: "#379657")
        jobCntLabel.clipsToBounds = true
        jobCntLabel.textAlignment = .center
        self.jobCntLabel = jobCntLabel
        self.contentView.addSubview(self.jobCntLabel)
        self.jobCntLabel.snp.makeConstraints { make in
            make.bottom.equalTo(-8)
            make.centerX.equalToSuperview()
            make.height.width.equalTo(16)
        }
        //weatherImageView
        let weatherImageView = UIImageView()
        self.weatherImageView = weatherImageView
        self.contentView.addSubview(weatherImageView)
        self.weatherImageView.snp.makeConstraints { make in
            make.left.equalTo(dateLabel.snp.right)
            make.centerY.equalTo(self.dateLabel)
            make.height.width.equalTo(10)
        }
        
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.titleLabel.isHidden = true//隐藏默认的选中背景titleLable，使用diy title label
        self.shapeLayer.isHidden = true//隐藏默认的选中背景layer，使用selectBackLayer
        //
        //selectBackLayer
        let contentBounds = self.contentView.bounds
        let selectBackSize: CGFloat = contentBounds.size.height
        let selectBackFrame = CGRect(x: contentBounds.origin.x + (contentBounds.size.width - selectBackSize) / 2, y: contentBounds.origin.y + (contentBounds.size.height - selectBackSize) / 2, width: selectBackSize, height: selectBackSize)
        self.selectBackLayer.frame = selectBackFrame
        self.selectBackLayer.path = UIBezierPath(roundedRect: self.selectBackLayer.bounds, cornerRadius: 6).cgPath
        
    }
    
    override func configureAppearance() {
        super.configureAppearance()
    }

}
